package com.rs.service.impl.rs;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rs.dao.AdjustmentMapper;
import com.rs.dao.AttendanceDao;
import com.rs.dao.AttendanceRulesMapper;
import com.rs.dao.BonusMapper;
import com.rs.dao.DepartmentDao;
import com.rs.dao.DepartmentMapper;
import com.rs.dao.PerforscMapper;
import com.rs.dao.PositionDao;
import com.rs.dao.ResignMapper;
import com.rs.model.Adjustment;
import com.rs.model.Attendance;
import com.rs.model.AttendanceRules;
import com.rs.model.Bonus;
import com.rs.model.Department;
import com.rs.model.Perforsc;
import com.rs.model.Position;
import com.rs.model.Resign;
import com.rs.service.rs.DepartmentService;


@Service
public class DepartmentServiceImpl implements DepartmentService{

	@Autowired
	private DepartmentMapper dm;
	
	@Override
	public List<Department> departmentAll() {
		// TODO Auto-generated method stub
		return dm.departmentAll();
	}
	@Override
	public Integer departmentAdd(Department department) {
		// TODO Auto-generated method stub
		return dm.departmentAdd(department);
	}
	@Override
	public Integer departmentDel(Department department) {
		// TODO Auto-generated method stub
		return dm.departmentDel(department);
	}
	@Override
	public Integer departmentUpdate(Department department) {
		// TODO Auto-generated method stub
		return dm.departmentUpdate(department);
	}
	
	
	@Autowired
	DepartmentDao dtd;
	@Autowired
	PositionDao ptd;
	@Autowired
	AttendanceDao att;
	@Autowired
	AttendanceRulesMapper arm;
	@Autowired
	AdjustmentMapper adm;
	@Autowired
	ResignMapper rsm;
	@Autowired
	BonusMapper bmr;
	@Autowired
	PerforscMapper perm;
	@Override
	public String addBuMen(Department dd) {
		// TODO Auto-generated method stub
		dtd.addBuMen(dd);
		return "添加成功";
	}

	@Override
	public List<Department> selBuMenAll() {
		// TODO Auto-generated method stub
		return dtd.selBuMenAll();
	}

	@Override
	public String delBuMen(Integer de_id) {
		// TODO Auto-generated method stub
		dtd.delBuMen(de_id);
		return "删除成功";
	}

	@Override
	public String UpdateBuMen(Department l1) {
		// TODO Auto-generated method stub
		dtd.UpdateBuMen(l1);
		return "编辑成功";
	}

	@Override
	public void addZhiwu(Position pp) {
		// TODO Auto-generated method stub
		Department dd = new Department();
		dd.setDe_name(pp.getBmname());
		Department d1 = dtd.selByname(dd);
		pp.setPo_deid(d1.getDe_id());
		ptd.addZhiwu(pp);
	}

	@Override
	public List<Position> positionSelectAll() {
		// TODO Auto-generated method stub
		return ptd.positionSelectAll();
	}

	@Override
	public String delZhiwu(Integer po_id) {
		// TODO Auto-generated method stub
		ptd.delZhiwu(po_id);
		return "删除成功";
	}

	@Override
	public String upDateZhiWu(Position l1) {
		// TODO Auto-generated method stub
		Department dd = new Department();
		dd.setDe_name(l1.getBmname());
		Department d1 = dtd.selByname(dd);
		l1.setPo_deid(d1.getDe_id());
		ptd.upDateZhiWu(l1);
		return "编辑成功";
	}

	@Override
	public List<Attendance> attendanceSelectByDay() {
		// TODO Auto-generated method stub
		return att.attendanceSelectByDay();
	}

	@Override
	public List<Attendance> selectByTiaojian(Attendance aa) {
		// TODO Auto-generated method stub
		if(null==aa.getState() || aa.getState().equals("")) {
			return att.attendanceByTiaojian(aa);
		}else {
			String state = aa.getState();
			if(state.equals("迟到")) {
				aa.setAt_amtype(2);
			}else if(state.equals("早退")) {
				aa.setAt_amtype(3);
			}else if(state.equals("缺卡")) {
				aa.setAt_amtype(4);
			}else if(state.equals("补卡")) {
				aa.setAt_amtype(5);
			}else if(state.equals("请假")) {
				aa.setAt_amtype(6);
			}else if(state.equals("出差")) {
				aa.setAt_amtype(7);
			}
			System.out.println("走了"+state+"++++"+aa.getAt_amtype());
			return att.attendanceByTiaojian(aa);
		}
		
	}

	@Override
	public List<Attendance> attendanceFindByDay(Attendance a1) {
		// TODO Auto-generated method stub
		return  att.attendanceFindByDay(a1);
	}

	@Override
	public AttendanceRules attendanceRulesFind() {
		// TODO Auto-generated method stub
		return arm.rarSelectAll();
	}

	@Override
	public void updateByPrimaryKey(AttendanceRules att1) {
		// TODO Auto-generated method stub
		arm.updateByPrimaryKey(att1);
		
	}

	@Override
	public List<Adjustment> adjustmentSelectAll() {
		// TODO Auto-generated method stub
		return adm.adjustmentAllPC();
	}

	@Override
	public List<Adjustment> adjustmentSelectByTiaojian(Adjustment a2) {
		// TODO Auto-generated method stub
		return adm.adjustmentSelectByTiaojian(a2);
	}

	@Override
	public List<Resign> ResignSelectAll() {
		// TODO Auto-generated method stub
		return rsm.ResignSelectAll();
	}

	@Override
	public List<Resign> resignSelectByTiaojian(Resign a2) {
		// TODO Auto-generated method stub
		return rsm.resignSelectByTiaojian(a2);
	}

	@Override
	public List<Bonus> bonusSelectAll() {
		// TODO Auto-generated method stub
		return bmr.bonusAllPC();
	}

	@Override
	public List<Bonus> bonusSelectByTiaojian(Bonus a2) {
		// TODO Auto-generated method stub
		return bmr.bonusSelectByTiaojian(a2);
	}

	@Override
	public List<Attendance> attendanceFindAll(Attendance a1) {
		// TODO Auto-generated method stub
		return att.attendanceFindAll(a1);
	}

	@Override
	public List<Attendance> attendanceFindAllname(Attendance a1) {
		// TODO Auto-generated method stub
		return att.attendanceFindAllname(a1);
	}

	@Override
	public List<Perforsc> PerforscSelectAll() {
		return null;
		// TODO Auto-generated method stub
//		return perm.PerforscSelectAll();
	}

}
